package com.uenpay.im.ui.old.activity.contacts;

import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;
import android.widget.TextView;

import com.uenpay.im.IMApplication;
import com.uenpay.im.R;
import com.uenpay.im.ui.old.activity.chat.ActivityHandle;
import com.uenpay.im.adapter.SearchResultUserListAdatper;
import com.uenpay.im.entities.QYXUserEntity;
import com.uenpay.util.app.base.BaseActivity;

import java.util.ArrayList;


/**
 * @author SL
 * @copyRight http://www.qiyunxin.com
 */
public class FriendsListActivity extends BaseActivity {

    private ListView listview;
    private SearchResultUserListAdatper adapter;
    private ArrayList<QYXUserEntity> list = null;

    @SuppressWarnings("unchecked")
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        isFullScreen = true;
        super.onCreate(savedInstanceState);
    }

    @Override
    public View bindView() {
        return null;
    }

    @Override
    public int bindLayout() {
        return R.layout.activity_list_layout;
    }

    @Override
    public void initView(View view) {
        list = (ArrayList<QYXUserEntity>) getIntent().getSerializableExtra(
                "result");
        initView();
        initListener();
        if (list != null) {
            adapter = new SearchResultUserListAdatper(FriendsListActivity.this,
                    list);
            listview.setAdapter(adapter);
        }
    }

    protected void initView() {
        ((TextView) findViewById(R.id.title_textview)).setText(getResources()
                .getString(R.string.search_result));
        listview = (ListView) findViewById(R.id.listview);
    }

    protected void initListener() {
        //返回键
        findViewById(R.id.back_layout).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View arg0) {
                finish();
            }
        });
        listview.setOnItemClickListener(new OnItemClickListener() {

            @Override
            public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
                                    long arg3) {
                QYXUserEntity user = (QYXUserEntity) arg0.getAdapter().getItem(
                        arg2);

                if (user != null) {
                    ActivityHandle.startUserDetailActivity(FriendsListActivity.this, user.custid);
                }

            }
        });
    }

    @Override
    protected void onDestroy() {
        IMApplication.getInstance().removeActivity(this);
        super.onDestroy();
    }

}
